<template>
  <div class="app-container">
    <el-page-header @back="goBack" content="我参与的检查"></el-page-header>
    <el-table
      :data="tableData"
      style="width: 100%; margin-bottom: 20px; margin-top: 20px"
      row-key="id"
      default-expand-all
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column label="组名" prop="groupName" v-if="groupName"> </el-table-column>
      <el-table-column prop="checkProjectIdsList" label="项目名称" width="180">
      </el-table-column>
      <el-table-column
        prop="bizEnterTask.finishTime"
        label="计划检查时间"
        width="180"
      >
      <template slot-scope="scope">
        {{scope.row.planStartTime}}至{{scope.row.planEndTime}}
      </template>
      </el-table-column>
      <el-table-column prop="bizEnterTask.finishTime" label="完成检查时间"> </el-table-column>
      <el-table-column prop="bizEnterTask.status" label="任务状态" align="center">
        <template slot-scope="scope">
          <el-tag
            effect="dark"
            :color="
              scope.row.bizEnterTask.status == '1'
                ? rgb1
                : scope.row.bizEnterTask.status == '2'
                ? rgb2
                : scope.row.bizEnterTask.status == '3'
                ? rgb3
                : rgb4
            "
            style="border: 0"
          >
            <dict-tag
              :options="dict.type.check_status"
              :value="scope.row.bizEnterTask.status"
            />
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="groupLeaderList" label="检查组长">
      </el-table-column>
      <el-table-column prop="groupMemberList" label="检查人数">
      </el-table-column>
      <el-table-column prop="bizEnterTask.hiddenNumber" label="隐患总数">
      </el-table-column>
      <el-table-column prop="bizEnterTask.rectifyResult" label="隐患整改情况">
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="goLookMyDate(scope.row)"
            v-if="scope.row.checkProjectIdsList"
            >查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getDataList } from "@/api/biz/enter/enter";
export default {
  dicts: ["check_status", "check_according"],
  data() {
    return {
      tableData: [],
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectId: this.$store.state.app.selectData,
        bizEnterCheckId: this.$route.query.id,
      },
      rgb1: "rgb(147, 210, 243)",
      rgb2: "rgb(255, 191, 107)",
      rgb3: "rgb(162, 239, 77)",
      rgb4: "rgb(144, 147, 153)",
      groupName:false,
    };
  },

  methods: {
    goLookMyDate(row) {
      this.$router.push({ name: "enterMyLookDate", query: { id: row.id } });
    },
    getList() {
      getDataList(this.queryParams).then((data) => {
        this.tableData = data.rows;
        this.total = data.total;
        this.tableData.forEach((item) => {
          item.checkProjectIdsList = item.checkProjectIdsList.join("、");
          item.groupLeaderList = item.groupLeaderList.join("、");
          item.groupMemberList = item.groupMemberList.length;
        });
        if (this.tableData[0].groupName != null) {
          this.groupName=true
          let arr = [];
          this.tableData.forEach((item) => {
            if (item.groupName != null) {
              if (!arr.includes(item.groupName)) {
                arr.push(item.groupName);
              }
            }
          });
          arr = arr.map((item) => ({ groupName: item }));
          arr.forEach((item) => {
            item.children = [];
            this.tableData.forEach((items) => {
              if (item.groupName == items.groupName) {
                item.children.push(items);
              }
            });
          });
          this.tableData = arr;
        }
      });
    },
    //返回
    goBack() {
      this.$router.push({ name: "Enter" });
      this.$store.state.tagsView.visitedViews =
        this.$store.state.tagsView.visitedViews.filter(
          (item) => item.name !== "enterMyLook"
        );
    },
  },

  components: {},

  computed: {},

  created() {
    this.getList();
  },
};
</script>
<style scoped></style>
